package interal

import "github.com/go-resty/resty/v2"

type Client struct {
}

func NewClient() *Client {
	return &Client{}

}

func (c *Client) GetTables() (error, *resty.Response) {
	client := resty.New()

	resp, err := client.R().
		EnableTrace().
		Get("http://localhost:3000/crud/tables")
	if err != nil {
		return err, nil
	}
	return nil, resp
}

func (c *Client) LoadColumns(tablename string) (error, *resty.Response) {
	client := resty.New()
	bodyStr := `{"table_name":"` + tablename + `"}`
	resp, err := client.R().
		SetHeader("Content-Type", "application/json").
		SetBody(bodyStr).
		Post("http://localhost:3000/crud/table_column")
	if err != nil {
		return err, nil
	}
	return nil, resp
}

func (c *Client) MakeController(tablename string) (error, *resty.Response) {
	client := resty.New()
	bodyStr := `{"table_name":"` + tablename + `"}`
	resp, err := client.R().
		SetHeader("Content-Type", "application/json").
		SetBody(bodyStr).
		Post("http://localhost:3000/table_column")
	if err != nil {
		return err, nil
	}
	return nil, resp
}

func (c *Client) MakeRouter(tablename string) (error, *resty.Response) {
	client := resty.New()
	bodyStr := `{"table_name":"` + tablename + `"}`
	resp, err := client.R().
		SetHeader("Content-Type", "application/json").
		SetBody(bodyStr).
		Post("http://localhost:3000/table_column")
	if err != nil {
		return err, nil
	}
	return nil, resp
}

func (c *Client) MakeRequest(tablename string) (error, *resty.Response) {
	client := resty.New()
	bodyStr := `{"table_name":"` + tablename + `"}`
	resp, err := client.R().
		SetHeader("Content-Type", "application/json").
		SetBody(bodyStr).
		Post("http://localhost:3000/table_column")
	if err != nil {
		return err, nil
	}
	return nil, resp
}
